﻿<%@page import="com.hh.bss.util.StringHelper" %>
<%
  String cvId=request.getParameter("cvId");  
  if (StringHelper.isEmpty(cvId)) cvId="0";
  String type=request.getParameter("type");  
%>
<!DOCTYPE html>  
<html>  
<head>  
    <meta charset="UTF-8">  
    <title>Basic Layout - jQuery EasyUI Demo</title> 

    <%@ include file="/WEB-INF/inc/default.jsp"%>
    <jsp:include page="/WEB-INF/inc/dic.jsp"/> 	    	
    
 <style type="text/css"> 
 	  html { font-size:12px; height:100%;} 
    body {MARGIN: 0px; font-size:12px; height:100%; }
 </style>    
<script type="text/javascript">  

   var cvId=<%=cvId%>;

            
</script>    
    
<body>  
  
 
             
         <div class="easyui-panel"  style="width:1180px;height:360px"> 
          <form id="fm" method="post" enctype="multipart/form-data" novalidate>  
             <input name="companyId" type="hidden">
             <input name="id" value="<%=cvId%>" type="hidden">
             <input name="contact_data" type="hidden">
	<table cellSpacing=0 cellPadding=0 class="dv-table" style="width:100%;border:1px solid #ccc;margin-top:0px">
	
	  
		<tr>
			<td>中文名<font color="red">*</font>:</td>
			<td><input name="cvName" class="easyui-box easyui-validatebox"  required="true"></td>
			<td>人选类别:</td>
			<td><input class="easyui-combobox" name="cvType" style="width:120px;"  data-options="data:__getCategory('CVTYPE'),valueField:'id', textField:'codeNameCn', multiple:false,panelHeight:'auto',mode:'remote' "></td>
			<td>现任公司<font color="red">*</font>:</td>
			<td><input name="company" required="true" class="easyui-box easyui-validatebox"><a href="#" class="easyui-linkbutton" onclick="javascript:selectCompany()">选择</a></td>
			<td>基本信息:</td>
			<td><input class="easyui-combobox"   name="nameInformer" style="width:120px;"  data-options="url:'/auth/systemUser/userlist.do',valueField:'account', textField:'name', multiple:false,panelHeight:'auto',mode:'remote' "></td>
		</tr>
		<tr style="border:10px;margin:5px;padding:5px">
			<td>英文名:</td>
			<td><input name="cvNameEn" class="easyui-box"></td>
			<td>人选标签:</td>
			<td><input class="easyui-combobox" name="cvTag" style="width:120px;"  data-options="data:__getCategory('CVTAG'),valueField:'id', textField:'codeNameCn', multiple:false,panelHeight:'auto',mode:'remote' "></td>
			<td>现任职位<font color="red">*</font>:</td>
			<td><input name="position" required="true" class="easyui-box easyui-validatebox"></td>
			<td>创建时间:</td>
			<td><input name="createDtString" disabled="true" class="easyui-box"></td>
		</tr>
		<tr>
			<td>性别<font color="red">*</font>：</td>
			<td><input class="easyui-combobox"  required="true" name="sex" style="width:50px;"  data-options="data:__getConstantCategory('SEX'),valueField:'code', textField:'value', multiple:false,panelHeight:'auto',mode:'remote' "></td>
			<td>所在部门:</td>
			<td><input name="dept" class="easyui-box"></td>
			<td>职级:</td>
			<td><input class="easyui-combobox" name="level" style="width:120px;"  data-options="data:__getCategory('JOBLEVEL'),valueField:'id', textField:'codeNameCn', multiple:false,panelHeight:'auto',mode:'remote' "></td>
			<td>简历录入人:</td>
			<td><input disabled="true" name="resumeCreator" class="easyui-box"></td>
		</tr>
		<tr>
			<td>学历:</td>
			<td><input class="easyui-combobox" name="degree" style="width:120px;"  data-options="data:__getCategory('DEGREE'),valueField:'id', textField:'codeNameCn', multiple:false,panelHeight:'auto',mode:'remote' "></td>
			<td>所在岗位</td>
			<td><input name="title" class="easyui-box"></td>
			<td>一级行业<font color="red">*</font>:</td>
			<td><input class="easyui-combobox" required="true" name="industry_parent" style="width:120px;"  data-options="data:__getCategoryByParant('INDUSTRY', 0),valueField:'id', textField:'codeNameCn', multiple:false,panelHeight:'auto',mode:'remote'
			,onSelect: function(rec){  
            
            $('#second_industry').combobox('loadData', __getCategoryByParant('INDUSTRY', rec.id));  
            $('#second_industry').combobox('setValue',null);
        }
			 "></td>
			 <td>简历录入时间:</td>
			<td><input name="resumeDtString" disabled="true" class="easyui-box"></td>
		</tr>
		<tr>
			<td>婚姻状况:</td>
			<td><input class="easyui-combobox" name="married" style="width:50px;"  data-options="data:__getConstantCategory('MARRIED'),valueField:'code', textField:'value', multiple:false,panelHeight:'auto',mode:'remote' "></td>
			<td>国籍:</td>
			<td><input class="easyui-combobox" name="nationality" style="width:120px;"  data-options="data:__getCategory('NATIONALITY'),valueField:'id', textField:'codeNameCn', multiple:false,panelHeight:'auto',mode:'remote' "></td>
			<td>二级行业<font color="red">*</font>:</td>
			<td><input class="easyui-combobox" required="true" id="second_industry" name="industry" style="width:120px;"  data-options="data:{},valueField:'id', textField:'codeNameCn', multiple:false,panelHeight:'auto',mode:'remote' "></td>
			<td>简历提供者:</td>
			<td><input class="easyui-combobox"   name="resumeInformer" style="width:120px;"  data-options="url:'/auth/systemUser/userlist.do',valueField:'account', textField:'name', multiple:false,panelHeight:'auto',mode:'remote' "></td>
		</tr>
		<tr>
			<td>外语水平</td>
			<td><input class="easyui-combobox" name="cvFlLevel" style="width:120px;"  data-options="data:__getConstantCategory('CvFLLevel'),valueField:'code', textField:'value', multiple:false,panelHeight:'auto',mode:'remote' "></td>
			<td>家庭地址:</td>
			<td><input name="address" class="easyui-box"></td>
			<td>一级职能<font color="red">*</font>:</td>
			<td><input class="easyui-combobox" required="true" name="function_parent" style="width:120px;"  data-options="data:__getCategoryByParant('JOB', 0),valueField:'id', textField:'codeNameCn', multiple:false,panelHeight:'auto',mode:'remote' 
			,onSelect: function(rec){              
            $('#second_job').combobox('loadData', __getCategoryByParant('JOB', rec.id));  
            $('#second_job').combobox('setValue',null);
        }
			"></td>
			<td>照片:</td>
			<td rowspan=4 valign="top">
			  <table>
			  <tr>
			  <td>
			  <div id='logopic'>
			  <img id="logo" name="logo" src="" width="140px" height="160px">
			  </div>
			  </td>
			  </tr>
			  <tr>
			  <td>
			  <input id="imageupload" name="imageupload" type="file" onchange="uploadfile(this);" style="width: 140px">
			  </td>
			  </tr>
			  </table>
			</td>
		</tr>
		<tr>
			<td>年薪范围</td>
			<td><input class="easyui-combobox" name="currentSalary" style="width:120px;"  data-options="data:__getCategory('SALARY'),valueField:'id', textField:'codeNameCn', multiple:false,panelHeight:'auto',mode:'remote' "></td>
			<td>邮政编码:</td>
			<td><input name="postCode" class="easyui-box"></td>			
			<td>二级职能<font color="red">*</font>:</td>
			<td><input class="easyui-combobox" required="true" id="second_job" name="function" style="width:120px;"  data-options="data:__getCategory('JOB'),valueField:'id', textField:'codeNameCn', multiple:false,panelHeight:'auto',mode:'remote' "></td>
			<td></td>
			<td></td>
		</tr>
		<tr>
			<td>开始工作年份:</td>
			<td><input name="workYear" class="easyui-datebox"></td>
			<td>出生年月:</td>
			<td><input name="birthdayString" data-options="formatter:formateDateShort" class="easyui-datebox"></td>
			<td>期望工作地:</td>
			<td><input class="easyui-combobox" name="expectLocation" style="width:120px;"  data-options="data:__getCategory('LOCATION'),valueField:'id', textField:'codeNameCn', multiple:false,panelHeight:250,mode:'remote' "></td>
			<td></td>
			<td></td>
		</tr>
		<tr>
		
			<td colspan=4 style="margin:5px;padding:5px">
			     <table id="dg_contact"  class="easyui-datagrid" style="width:500px;height:115px"  
                            url="/talent/cvContactDetail/list.do?cv_id=<%=cvId%>"  
                            toolbar="#toolbar"  data-options="onClickRow:onClickRow" 
                            rownumbers="true" fitColumns="true" singleSelect="false">  
                            <thead>  
                                <tr>  
                                    
                                    <th field="id" hidden="true" width="50">id</th>
                                    <th field="contactType" width="50"
                                    	editor="{
                                         type:'combobox',
                                         options:{
                                             valueField:'code',
                                             textField:'value',
                                             panelHeight:'auto',
                                             data:__getConstantCategory('ContactType'),
                                             required:true
                                             ,onSelect: function(rec){
                                              //alert(rec.code);
                                              //editIndex
                                              if (editIndex == undefined){return};
                                              
                                              setContactEdit(rec.code);
                                              
                                            }
                                         }
                                         
                                      }"
                                    	formatter="formatContact" >联系方式</th>  
                                    <th field="nbrExt1" editor='text' width="50">区号</th>  
                                    <th field="nbr" editor='validatebox' required="true" width="50">号码</th>  
                                    <th field="nbrExt2" editor='validatebox' width="50">分机号</th>  
                            
                                </tr>  
                            </thead>  
                      </table>
			</td>
			
			<td colspan=2 valign="top">
			<table>
			<tr>
			
			<td align="left" valign="top" style="padding-top:5px">当前所在地:
			
			</td>
			<td align="left" valign="top" style="padding-top:5px"><input class="easyui-combobox" name="currentAddress" style="width:120px;"  data-options="data:__getCategory('LOCATION'),valueField:'id', textField:'codeNameCn', multiple:false,panelHeight:250,mode:'remote' "></td>
			
			</tr>
			<tr>
			
			<td align="left" valign="top" style="padding-top:5px">简历完整度:
			
			</td>
			<td align="left" valign="top" style="padding-top:5px"><input class="easyui-combobox" name="integrity" style="width:120px;"  data-options="data:__getConstantCategory('CvIntegrity'),valueField:'code', textField:'value', multiple:false,panelHeight:'auto',mode:'remote' "></td>
			
			</tr>			
			<tr>
			<td colspan=2><a href="#" class="easyui-linkbutton" onclick="javascript:save()">保存</a>
			<a href="#" class="easyui-linkbutton" onclick="javascript:closeWin()">关闭</a>
			</td>
			</tr>
			</table>
			</td>
			
			<td></td>
			<td></td>
		</tr>
		
		
	</table>                  
	        		     	        	  	   	

	        		   
	        		       
           </form>  
         </div> 
           
        </div>
       <!---上面区域(结束)--->
            
 
    <div id="toolbar">  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="append()">新增</a>          
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="removeit()">删除</a>         
    </div> 
    

   

    
<style type="text/css">  
        #fm{  
            margin:0;  
            padding:10px 30px;  
        }  
        .ftitle{  
            font-size:14px;  
            font-weight:bold;  
            padding:5px 0;  
            margin-bottom:10px;  
            border-bottom:1px solid #ccc;  
        }  
        .fitem{  
            margin-bottom:5px;  
        }  
        .fitem label{  
            display:inline-block;  
            width:80px;  
        }  
    </style> 
    
    <script type="text/javascript">  
     	  
        var selectCompanyWin;
        var url='/talent/cv/save.do';
        <%if ("UPDATE".equals(type)){ %>
            url='/talent/cv/update.do';
        <% }%>
        

        function save(){    
        	  //设置
        	  $("#dg_contact").datagrid("acceptChanges"); 
        	 
        	  var datas = $("#dg_contact").datagrid("getData");
        	  //console.log(datas);
        	  //console.log(datas.rows);
        	  
        	 var flag = false; 
        	 for (var i = 0; i < datas.rows.length; i++) {
        	     
        	     var contactType = datas.rows[i].contactType; // 联系类型
						   var nbrExt1 = datas.rows[i].nbrExt1; // 区号
						   var nbr = datas.rows[i].nbr; // 号码
						   // 手机
				    		if (contactType == 'M') {
				    			var pattern = /^\d+$/;
				    			if (!pattern.test(nbr)) {
				    				
				    				$.messager.alert('提示',"手机号码不合法.",'info');
				    				return;
				    			}
            
				    		}
				    		// 邮件
				    		if (contactType == 'E') {
				    			var pattern = /^\w+([-+.]\w+)*@\w+([-.]\w+)*.\w+([-.]\w+)*$/;
				    			if (!pattern.test(nbr)) {
				    				
				    				$.messager.alert('提示',"邮件地址不合法.",'info');
				    				return;
				    			}
            
				    		}
				    		// 电话
				    		if (contactType == 'D') {
				    			var pattern = /^\d+$/;
				    			if (!pattern.test(nbr)) {
				    				
				    				$.messager.alert('提示',"电话号码不合法.",'info');
				    				return;
				    			}
            
				    		}
            
				    		if (nbr) {
				    			nbr = nbr.replace(/^\s+|\s+$/g, ""); // 去两头的空格
				    		}
            
				    		if (nbrExt1 != null && nbrExt1 != '') {
				    			if (isNaN(nbrExt1)) {
				    				alert("请输入正确的区号(2-4的数字).");
				    				return;
				    			}
				    		}
				    		if (nbr != null && nbr != '') {
				    			flag = true;
				    		}
        	 
        	 }
        	 if (!flag) {
						
						 $.messager.alert('提示',"请填写联系方式.",'info');
						 return;
					}
        	 
        	  var contact_data = JSON.stringify(datas.rows); 
        	 
        	  $('#fm input[name="contact_data"]').attr("value",contact_data);
        	 
        	  
            $('#fm').form('submit',{  
                url: url,  
                onSubmit: function(){  
                	  //判断现任公司是否选择
                	  
                    return $(this).form('validate');  
                },  
                success: function(result){  
                    var result = eval('('+result+')');  
                    console.log(result);
                    if (result.success == true){  
                        //$.messager.alert('信息',result.msg,'info');  
                        alert(result.msg);
                        if (refresh) refresh();
                        
                        <%if (!"UPDATE".equals(type)){ %>
                            if (closeWin) closeWin();
                        <% }%>
                        
                        //$('#dlg').dialog('close');     
                        
                        //$('#dg').datagrid('reload'); 
                    } else {  
                        $.messager.alert('错误',result.msg,'error');
                    }  
                }  
            });  
        }  
        
        $('#fm').form({
        	    onLoadSuccess: function(data){
        	     
        	    	//处理一二级行业
        	    	console.log(data.industry);
        	    	
        	    	var industry=data.industry?data.industry.toString():null;
        	    	
        	    	
        	    	var functionStr=data.function?data.function.toString():null;
        	    	
        	    	var industry_parent = __getCategoryCodeParant('INDUSTRY', industry); // 加载职能
        	    	
        	    	//$('#fm input[comboname="industry_parent"]').attr("value",industry_parent);
        	    	$('#fm input[comboname="industry_parent"]').combobox("setValue",industry_parent);
        	    		//alert(industry+'--'+industry_parent);
        	    	$('#fm input[comboname="industry"]').combobox('loadData',__getCategoryByParant('INDUSTRY', industry_parent));
        	    	
        	    	//处理一二级职能
        	    	var function_parent = __getCategoryCodeParant('JOB', functionStr); // 加载职能
        	    	//$('#fm input[comboname="function_parent"]').attr("value",function_parent);
        	    	$('#fm input[comboname="function_parent"]').combobox("setValue",function_parent);
        	    	//alert(functionStr+'--'+function_parent);
        	    	$('#fm input[comboname="function"]').combobox('loadData',__getCategoryByParant('JOB', function_parent));
        	    	
        	    	//设置图片
        	    	$('#logo').attr("src",data.logo);
        	    	
        	    }
        });
        
     	     
        function uploadfile(file){
        
                 var div = document.getElementById('logopic');  
                 if (file.files && file.files[0])  
                 {  
                  //for ff or chrome
                   div.innerHTML = '<img id="logo" name="logo" width=140 height=160 >';     
                   var img = document.getElementById('logo');                        
                   var reader = new FileReader();  
                   reader.onload = function(evt){img.src = evt.target.result;}  
                   reader.readAsDataURL(file.files[0]);  
                   
                 }  
                 else  
                 {                  
                   //for ie   
                   file.select();  
                   var src = document.selection.createRange().text;  
                   div.innerHTML = '<img id=imghead width=140 height=160 style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);">';  
                   var img = document.getElementById('logo'); 
                   img.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = src;     
                 }
        
        }
        

                 function setCompany(company){
                          $('#fm input[name="company"]').attr("value",company.name);
                          $('#fm input[name="companyId"]').attr("value",company.id);
                 }
              
                 
              
              
                 function selectCompany(){
        	           if (selectCompanyWin)
                            selectCompanyWin.window('open');
                        else selectCompanyWin = $.window({
		                 	   	title:"选择公司",
		                 	   	url:"/customer/company/selectCompanyPage.do",
		                 	   	isIframe:true,
		                 	   	height:380,
		                 	   	modal:false,		      	   	
		                 	   	width:1000,
		                 	   	onComplete:function(jq,iframe){	
		                 	   		   console.log(iframe);       	   		   	      	   		
		                 	   		   var fwindow = $.window.util.getFrameWindow(iframe);		      	   		
		                 	   		   var ijq = fwindow.jQuery;		
		                 	   		   var curWin=this;   
		                 	   		   
		                 	   		   var curWin=this;
					           
					                      fwindow.closeWin=function(){
					                      	   curWin.window('close');
					                      	  
				                        };
				                        
				                        fwindow.callback=curWin.openerWin.setCompany;
				                        //fwindow.pcallback=curWin.openerWin.addCompanyDB;
		                 	   		   //alert(fwindow.pcallback2);
		                 	   	}
		                 	});
		                 	selectCompanyWin.openerWin=window;  
                  }
              
                        
                 function formatContact(value,row,index){
                       	return __getConstantCategoryCodeValue('ContactType', value);
                    }

     </script>
     
      <script type="text/javascript">
        var editIndex = undefined;
        function endEditing(){
            if (editIndex == undefined){return true}
            if ($('#dg_contact').datagrid('validateRow', editIndex)){
               // var ed = $('#dg_contact').datagrid('getEditor', {index:editIndex,field:'productid'});
                //var productname = $(ed.target).combobox('getText');
                //$('#dg_contact').datagrid('getRows')[editIndex]['productname'] = productname;
                $('#dg_contact').datagrid('endEdit', editIndex);
                editIndex = undefined;
                return true;
            } else {
                return false;
            }
        }
        function setContactEdit(type){
           if (editIndex == undefined){return}
           var ed_nbrExt1 = $('#dg_contact').datagrid('getEditor', {index:editIndex,field:'nbrExt1'});
           var ed_nbrExt2 = $('#dg_contact').datagrid('getEditor', {index:editIndex,field:'nbrExt2'});
                                              
                     
           if (type=='D'){
                     $(ed_nbrExt1.target).removeAttr("disabled");
                     $(ed_nbrExt2.target).removeAttr("disabled");
                    
           }else{
                     $(ed_nbrExt1.target).attr('disabled','true');
                     $(ed_nbrExt2.target).attr('disabled','true');
                    
           }
           if (type=='E'){
              var ed_nbr = $('#dg_contact').datagrid('getEditor', {index:editIndex,field:'nbr'});
              $(ed_nbr.target).validatebox({validType:'email'});
           }
        }
        function onClickRow(index){
            if (editIndex != index){
                if (endEditing()){
                    $('#dg_contact').datagrid('selectRow', index)
                            .datagrid('beginEdit', index);
                    editIndex = index;
                    var ed = $('#dg_contact').datagrid('getEditor', {index:editIndex,field:'contactType'});
                    var ContactType = $(ed.target).combobox('getValue');
                    setContactEdit(ContactType);
                                        
                } else {
                    $('#dg_contact').datagrid('selectRow', editIndex);
                }
            }
        }
        function append(){
            if (endEditing()){
                //$('#dg_contact').datagrid('appendRow',{});
                $('#dg_contact').datagrid('appendRow',{contactType:'M'});
                setContactEdit('M');
                editIndex = $('#dg_contact').datagrid('getRows').length-1;
                $('#dg_contact').datagrid('selectRow', editIndex)
                        .datagrid('beginEdit', editIndex);
               // optWin.doForm.find('input[itemId="currency"]').combobox("setValue","RMB");        
            }
        }
        function removeit(){
            if (editIndex == undefined){return}
            $('#dg_contact').datagrid('cancelEdit', editIndex)
                    .datagrid('deleteRow', editIndex);
            editIndex = undefined;
        }	
      </script>  
</body>  
</html>
<script>
	<%if ("UPDATE".equals(type)){ %>
            $('#fm').form('load','/talent/cv/get.do?id='+cvId);
  <% }%>
  
</script>
